package org.hackystat.devcathlon.ui.page.scoreboard.gameinfopanel;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.hackystat.devcathlon.engine.match.Match;
import org.hackystat.devcathlon.engine.team.Team;
import org.hackystat.devcathlon.ui.DevcathlonSession;
import org.hackystat.devcathlon.ui.page.matches.MatchesSession;

/**
 * The panel is a holder for team images and score.
 *  
 * @author Daniel Arakaki
 *
 */
public class FrontInfoPanel extends Panel implements Serializable {
  
  /** Support serialization. */
  private static final long serialVersionUID = 1L;

  /**
   * Initialize sessions, add elements to Game Information panel. 
   * 
   * @param id The Wicket id from the scoreboard page.
   * @param matchList A list of Matches.
   */
  public FrontInfoPanel(String id, List<Match> matchList) {
    super(id);
    DevcathlonSession devcathlonSession = DevcathlonSession.get();
    MatchesSession matchesSession = devcathlonSession.getMatchesSession();
    matchesSession.toString();
    String noMatch = "";
    
    if (matchList.isEmpty()) {
      noMatch = "";
      add(new Label("matchNameHeader", ""));
      add(new Label("teamOneName", ""));
      add(new Label("scoreOne", ""));
      add(new Label("teamTwoName", ""));
      add(new Label("scoreTwo", ""));
    } 
    else {
      Match match = matchList.get(0);
      List<Team> teamList = new ArrayList<Team>(matchList.get(0).getTeams());

      add(new Label("matchNameHeader", matchList.get(0).getName()));
      add(new Label("teamOneName", teamList.get(0).getName()));
      add(new Label("scoreOne", match.getTeamPoints(teamList.get(0)).toString()));
      add(new Label("teamTwoName", teamList.get(1).getName()));
      add(new Label("scoreTwo", match.getTeamPoints(teamList.get(1)).toString()));
    }
    add(new Label("noMatch", noMatch));
  }
}

